package com.yiaohuer.entity;

import com.yiaohuer.enums.ResultCodeEnum;
import lombok.Data;

import static com.yiaohuer.enums.ResultCodeEnum.*;

@Data
public class Result<T> {

    private Boolean success;

    private Integer code;

    private String message;

    private T data;

    public static Result ok(){
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(SUCCESS.getCode());
        result.setMessage(SUCCESS.getDesc());
        return result;
    }

    public static <T> Result ok(T data){
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(SUCCESS.getCode());
        result.setMessage(SUCCESS.getDesc());
        result.setData(data);
        return result;
    }

    public static Result fail(){
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(FAIL.getCode());
        result.setMessage(FAIL.getDesc());
        return result;
    }

    public static <T> Result fail(T data){
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(FAIL.getCode());
        result.setMessage(FAIL.getDesc());
        result.setData(data);
        return result;
    }

}
